package com.pluten.web.controller.basicinfo;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.pluten.common.annotation.Log;
import com.pluten.common.core.controller.BaseController;
import com.pluten.common.core.domain.AjaxResult;
import com.pluten.common.enums.BusinessType;
import com.pluten.basicinfo.domain.CmProductCategory;
import com.pluten.basicinfo.service.ICmProductCategoryService;
import com.pluten.common.utils.poi.ExcelUtil;
import com.pluten.common.core.page.TableDataInfo;

/**
 * 产品类别Controller
 * 
 * @author wangjun
 * @date 2021-08-24
 */
@RestController
@RequestMapping("/basicinfo/category")
public class CmProductCategoryController extends BaseController
{
    @Autowired
    private ICmProductCategoryService cmProductCategoryService;

    /**
     * 查询产品类别列表
     */
    @PreAuthorize("@ss.hasPermi('basicinfo:category:list')")
    @GetMapping("/list")
    public TableDataInfo list(CmProductCategory cmProductCategory)
    {
        startPage();
        List<CmProductCategory> list = cmProductCategoryService.selectCmProductCategoryList(cmProductCategory);
        return getDataTable(list);
    }

    /**
     * 导出产品类别列表
     */
    @PreAuthorize("@ss.hasPermi('basicinfo:category:export')")
    @Log(title = "产品类别", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(CmProductCategory cmProductCategory)
    {
        List<CmProductCategory> list = cmProductCategoryService.selectCmProductCategoryList(cmProductCategory);
        ExcelUtil<CmProductCategory> util = new ExcelUtil<CmProductCategory>(CmProductCategory.class);
        return util.exportExcel(list, "产品类别数据");
    }

    /**
     * 获取产品类别详细信息
     */
    @PreAuthorize("@ss.hasPermi('basicinfo:category:query')")
    @GetMapping(value = "/{guid}")
    public AjaxResult getInfo(@PathVariable("guid") Long guid)
    {
        return AjaxResult.success(cmProductCategoryService.selectCmProductCategoryById(guid));
    }

    /**
     * 新增产品类别
     */
    @PreAuthorize("@ss.hasPermi('basicinfo:category:add')")
    @Log(title = "产品类别", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CmProductCategory cmProductCategory)
    {
        return toAjax(cmProductCategoryService.insertCmProductCategory(cmProductCategory));
    }

    /**
     * 修改产品类别
     */
    @PreAuthorize("@ss.hasPermi('basicinfo:category:edit')")
    @Log(title = "产品类别", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CmProductCategory cmProductCategory)
    {
        return toAjax(cmProductCategoryService.updateCmProductCategory(cmProductCategory));
    }

    /**
     * 删除产品类别
     */
    @PreAuthorize("@ss.hasPermi('basicinfo:category:remove')")
    @Log(title = "产品类别", businessType = BusinessType.DELETE)
	@DeleteMapping("/{guids}")
    public AjaxResult remove(@PathVariable Long[] guids)
    {
        return toAjax(cmProductCategoryService.deleteCmProductCategoryByIds(guids));
    }
}
